/***
 *
 * @param data
 * @param childs
 * @constructor
 */
var Node = function (data, childs) {
	this.data = data;
	this.parent = undefined;
	this.childs = childs || [];     //childrens node list.
	this.height = 0;
};

Node.prototype = {
	constructor: Node,
	init: function () {
		var childs = this.childs;
		for (var i = 0; i < childs.length; i++) {
			childs[i].parent = data;
		}
	},
	isRoot: function () {
		return this.height === 0;
	},
	isLeaf: function () {
		return this.childs.length === 0;
	},
	append: function (node) {
		node.parent = this;
		this.childs.push(node);
	},
	parents:function(){
		var parentsData = [],
			node= this.cloneNode();

		while (node.height > 0) {
			parentsData.push(node.data);
			node = node.parent;
		}

		return parentsData;
	},
	cloneNode:function(){
		return $.extend(true,{},this);
	},
	toString: function () {
		console.log(this.data);
	}
};


